<template>
  <div class="login">
    <el-row>
      <!-- row是行 col是列  一行总共24列 平均分配 满24份就换行 -->
      <el-col :span="12" :offset="6">
        <div class="login-content">
          <h1>登录</h1>
          <el-form
            :model="ruleForm"
            :rules="rules"
            ref="ruleForm11"
            label-width="100px"
            class="demo-ruleForm"
          >
            <el-form-item label="用户名" prop="username">
              <el-input v-model="ruleForm.username"></el-input>
            </el-form-item>
            <el-form-item label="密码" prop="password">
              <el-input show-password v-model="ruleForm.password"></el-input>
            </el-form-item>

            <el-form-item>
                <!-- 覆盖elementui的默认样式 -->
              <el-button class="login-btn" type="primary" @click="submitForm()"
                >登录</el-button
              >
            </el-form-item>
          </el-form>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import {Login} from '../http'
export default {
  data() {
    return {
      ruleForm: {
        username: "AAA",
        password: "admin",
      },
      rules: {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
          { min: 3, max: 15, message: "长度在 3 到 15 个字符", trigger: "blur" },
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" }
        ]
      },
    };
  },
  methods: {
    submitForm() {
        // this.$refs 这是选择组件 可以在父组件中调用子组件的函数 比如validate
      this.$refs.ruleForm11.validate( async (valid) => {
        if (valid) {
          // action = axios + mutation
          this.$store.dispatch('getUserinfo', this.ruleForm)
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>

<style scoped>
.login {
  width: 100vw;
  height: 100vh;
  background-color: #56a5f1;
}
.login-content {
  height: 400px;
  margin-top: 100px;
  background-color: #fff;
  border-radius: 10px;
}
.login .login-btn {
    border-color: chocolate;
    background-color: chocolate;
}
</style>